#include<bits/stdc++.h>
using namespace std;
char c[1005],opt[10];
int Q,Head[9909],hcnt,mod=9901,len,bj[5]= {255,255,255,255,65535},Scnt;
struct id {
	int o[5],Sid,next;
} Hash[1005],cn;
short pan() {
	int cpos=0,p=1,shouldread=1,num,numpos=0,zeronum=0;
	while(cpos<len) {
		if(shouldread) {
			shouldread=0,zeronum=0,num=0;
			if(48<=c[cpos] && c[cpos]<=57) {
				if(numpos>4)
					return 1;
				for(; 48<=c[cpos] && c[cpos]<=57 && cpos<=len; ++cpos) {
					num=(num<<1)+(num<<3)+(c[cpos]&15);
					if(zeronum && num){
						return 1;
					}
					else if(num==0) {
						++zeronum;
						if(zeronum>1)
							return 1;
					} else if(num>bj[numpos])
						return 1;
				}
				cn.o[numpos++]=num;
			} else return 1;
		} else {
			if(p==0)
				return 1;
			if(p<4 && c[cpos]=='.')
				++p;
			else if(p==4 && c[cpos]==':')
				p=0;
			else
				return 1;
			++cpos,shouldread=1;
		}
	}
	if(numpos!=5 || p){
		return 1;
	}
	return 0;
}
int h(id t) {
	int x=(t.o[0]+t.o[1]*t.o[2]%mod+t.o[3]+t.o[4])%mod;
	for(int pos=Head[x]; pos!=0; pos=Hash[pos].next) {
		if(t.o[0]==Hash[pos].o[0] && t.o[1]==Hash[pos].o[1] && t.o[2]==Hash[pos].o[2] && t.o[3]==Hash[pos].o[3] && t.o[4]==Hash[pos].o[4]) {
			return Hash[pos].Sid;
		}
	}
	return 0;
}
void puth(id t) {
	int x=(t.o[0]+t.o[1]*t.o[2]%mod+t.o[3]+t.o[4])%mod;
	Hash[++hcnt]=t;
	Hash[hcnt].next=Head[x];
	Head[x]=hcnt;
}
int main() {
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&Q);
	short p;
	int ha;
	Scnt=0;
	while(Q--) {
		++Scnt;
		scanf("%s",&opt);
		scanf("%s",&c);
		len=strlen(c);
		p=pan();
		if(p) {
			puts("ERR");
			continue;
		}
		cn.Sid=Scnt;
		if(opt[0]=='S') {
			if(h(cn)) {
				puts("FAIL");
			} else {
				puth(cn);
				puts("OK");
			} 
		} else {
			ha=h(cn);
			if(ha){
				printf("%d\n",ha);
			}
			else{
				puts("FAIL");
			}
		}
	}
	return 0;
}

